//package com.studerb.tasks;
//
//import java.util.ArrayList;
//import java.util.List;
//import java.util.concurrent.BlockingQueue;
//import java.util.concurrent.Callable;
//
//import org.apache.log4j.Logger;
//import org.springframework.beans.factory.annotation.Autowired;
//
//import com.studerb.model.NewsGroup;
//import com.studerb.service.NewsGroupService;
//import com.studerb.util.Constants;
//
//public class ListCommandConsumerTask implements Callable<List<NewsGroup>> {
//
//    private final static Integer LOG_COUNT = 10000;
//    private final static Logger log = Logger.getLogger(ListCommandConsumerTask.class);
//
//    private BlockingQueue<String> queue;
//    @Autowired private NewsGroupService groupService;
//    private int rejected = 0;
//    private int count = 0;
//
//    public ListCommandConsumerTask() {
//    }
//
//    public List<NewsGroup> call() throws Exception {
//
//        String line;
//        List<NewsGroup> subscribed = groupService.getSubscribed();
//        log.info(subscribed.size() + " subscribed groups to update");
//        List<NewsGroup> tempGroups = new ArrayList<NewsGroup>();
//
//        while(true){
//            line = queue.take();
//            if( ++count % LOG_COUNT == 0)
//                log.debug(count + ": " + line);
//
//            // end of queue - finish updating to database last groups
//            if(line.equals(Constants.END_OF_QUEUE)){
//                log.info("Received END_OF_QUEUE: " + line);
//                break;
//            }
//
//            // create a new newsgroup by parsing the string
//            NewsGroup group = NewsGroup.createNewsGroup(line);
//            if(group == null){
//                ++rejected;
//                continue;
//            }
//            else
//                tempGroups.add(group);
//        }
//        log.info("Obtained: " + tempGroups.size() + " new groups");
//        log.info("Rejected " + this.rejected + " newsgroups");
//        return tempGroups;
//    }
//
//    public void setQueue(BlockingQueue<String> queue) {
//        this.queue = queue;
//    }
//}
